package top.imyzt.util;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;

/**
 * 集合工具类
 * @author imyzt
 *
 */
public class CollectionUtils {

	
	/**
	 * List去重
	 * @param list
	 * @return
	 */
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public static <T> List<?> distinct(List<?> list){
		HashSet h = new HashSet(list);   
		list.clear();   
		list.addAll(h); 
		return list;
	}
	
	@SuppressWarnings("unchecked")
	public static void main(String[] args) {
		List<Integer> list = new ArrayList<Integer>();
		list.add(4);
		list.add(2);
		list.add(1);
		list.add(1);
		list.add(1);
		list.add(1);
		for (int i = 0; i < list.size(); i++) {
			System.out.println(list.get(i));
		}
		System.out.println("-----------");
		List<Integer> list1 = (List<Integer>) distinct(list);
		for (int i = 0; i < list1.size(); i++) {
			System.out.println(list.get(i));
		}
	}
}
